<template>
  <div :class="className" :style="{height:height,width:width,top:top, 'font-size': Math.round(5400/100) + 'px'}"/>
</template>

<script>
import * as echarts from 'echarts' // echarts theme
import drawMixin from "@/utils/drawMixin";
// import {getOrganAntifraudInfo} from "@/api/apiOrganAntifraud";

//授信笔数
const animationDuration = 7000

export default {
  name: 'DoubleBar',
  mixins: [drawMixin],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    top: {
      type: String,
      default: '5%'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '100%'
    }
  },

  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
    this.getChartData()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
    clearInterval(this.chartTimer);
  },

  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOptions()
    },

    getChartData() {
      getOrganAntifraudInfo().then(res => {
        console.log('double bar')
        console.log(res)
      })
    },

    setOptions() {
      this.chart.clear()
      this.chart.setOption({
        animationDuration: animationDuration,
        animationDurationUpdate: animationDuration,
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'none'
          }

        },
        legend: {
          show: true,
          top: '10%',
          itemWidth: 20,
          itemHeight: 5,
          textStyle: {
            fontSize: 12,
            lineHeight: 12,
            rich: {
              a: {
                verticalAlign: 'middle',
              },
            },
            padding: [0, 0, -2, 0],  //[上、右、下、左]
          },
        },
        grid: {
          left: '3%',
          right: '5%',
          bottom: '8%',
          containLabel: true
        },
        yAxis: {
          type: 'value',
          name: "单位：笔数",
          nameTextStyle: {
            color: " rgba(77,77,77,0.70)",
            fontSize: 12,
            padding: 0
          },
          splitLine: {
            show: false,
            lineStyle: {
              color: '#D2E6F9',
              type: 'dashed'
            }
          },
          axisLine: {
            lineStyle: {
              color: '#E0E0E0'
            }
          },
          axisTick: {
            show: false
          },
          axisLabel: {
            color: '#000'
          }
        },
        xAxis: [{
          type: 'category',
          data: ['2023.01', '2023.02', '2023.03', '2023.04', '2023.05', '2023.06', '2023.07'],
          axisLine: {
            lineStyle: {
              color: '#E0E0E0'
            }
          },
          axisTick: {
            show: false
          },
          axisLabel: {
            color: '#888888'
          }
        }, {
          type: 'category',
          axisLine: {
            show: false
          },
          axisTick: {
            show: false
          },
          axisLabel: {
            show: false
          }
        }],
        series: [
          {
            name: '实时请求',
            xAxisIndex: 1,
            type: 'bar',
            barWidth: 24,
            barGap: '1%',
            data: [2, 4, 6, 8, 10, 12, 14],
            label: {
              show: true,
              fontSize: 14,
              color: '#888888',
              formatter: '{c}',
              position: 'top'
            },
            itemStyle: {
              color: "#eaf9a6",
              borderColor: "rgba(145,252,243,0.75)",
              borderWidth: 1,
              borderType: 'solid',
            }
          },
          {
            name: '实时反馈',
            type: 'bar',
            barWidth: 24,
            barGap: '1%',
            data: [1, 2, 3, 4, 5, 6, 7],
            "label": {
              show: true,
              formatter: '{c}',
              "position": "left",
              color: 'rgba(119,167,255,1)',
              fontSize: 12,
              textAlign: 'center'
            },
            color: "#80cdf5"
          },
          {
            name: '批量请求',
            xAxisIndex: 1,
            type: 'bar',
            barWidth: 24,
            barGap: '1%',
            data: [6, 12, 18, 24, 30, 36, 42],
            "label": {
              normal: {
                show: true,
                fontSize: 14,
                color: '#888888',
                formatter: '{c}',
                position: 'top'
              }
            },
            itemStyle: {
              color: "#5bb822",
              borderColor: "#9ef552",
              borderWidth: 1,
              borderType: 'solid',

            }
          }, {
            name: '批量反馈',
            type: 'bar',
            barWidth: 24,
            barGap: '1%',
            data: [3, 6, 9, 12, 15, 18, 21],
            "label": {
              show: true,
              formatter: '{c}',
              "position": "right",
              color: 'rgba(119,167,255,1)',
              fontSize: 12,
              textAlign: 'center'
            },
            color: "#edc675"
          }

        ]
      })
    }
  }
}
</script>
